<?php
namespace Admin\Controller;
use Think\Model;
use Admin\Controller\CommonController;
/**
 *员工类
 * User: xj
 * Date: 2015/3/23
 * Time: 16:27
 */
class StaffController extends  CommonController
{
    /*
     * 员工管理页面
     *
     * */
    protected  $groupModel;
    protected  $staffModel;
    public  function __construct()
    {
        parent::__construct();
        $this->groupModel=D('Group');
        $this->staffModel=D('Staff');

    }
    public function index()
    {
        //头部输出
        $this->head();

        $allGroup=$this->groupModel->getAllGroup();
        $page=I('get.p');

        $count=$this->staffModel->counts();//获取所有记录总数

        $pageSize=25;//每页显示数
        $staff=$this->staffModel->getStaff(NUll,$page,$pageSize);//获取所有记录

        //分页
        $page=new PageController($count,$pageSize);
        $show=$page->show();


        $this->assign('page',$show);
        $this->assign('group',$allGroup);
        $this->assign('staff',$staff);
        $this->display();
    }

    /*
     * 添加员工与编辑员工页面
     * */
    public function update()
    {
        $this->head();//头部输出
        $_GET['nav_id']=2;//设定导航高亮
        $staff_id=I('get.staff_id');
        if($staff_id)
        {
            $staff=$this->staffModel->getStaff($staff_id);
            $this->assign('staff',$staff);
        }
        else
        {
            $this->add();
        }
        $this->display();

    }

    public function edit()
    {

        if($this->staffModel->create())
        {

           $this->staffModel->save();
            $this->success('编辑成功');
        }

    }
    public function add()
    {

        if($this->staffModel->create())
        {

            $this->staffModel->add();
            $this->success('新增成功');
        }


    }
    public function del()
    {
        $map['staff_id']=I('get.staff_id');
        $data['state']=0;
        $this->staffModel->where($map)->save($data);
        $this->success('删除成功');
    }


}